package com.zkteco.android.IDReader

import android.graphics.Bitmap
import okhttp3.internal.and

/**
 * Created by scarx on 2015/12/3.
 */
object IDPhotoHelper {
    @JvmStatic
    fun Bgr2Bitmap(bgrbuf: ByteArray): Bitmap {
        val width = WLTService.imgWidth
        val height = WLTService.imgHeight
        val bmp = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565)
        var row = 0
        var col = width - 1
        var i = bgrbuf.size - 1
        while (i >= 3) {
            var color: Int = bgrbuf[i] and 0xFF
            color += bgrbuf[i - 1].toInt() shl 8 and 0xFF00
            color += bgrbuf[i - 2].toInt() shl 16 and 0xFF0000
            bmp.setPixel(col--, row, color)
            if (col < 0) {
                col = width - 1
                row++
            }
            i -= 3
        }
        return bmp
    }
}